home *** CD-ROM | disk | FTP | other *** search
/ Assassins - Ultimate CD Games Collection 4 / Assassins 4 (1999)(Weird Science).iso / misc / omega / source / omega.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-02  |  12.0 KB  |  394 lines

  1. /* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
  2.  
  3. /* this file includes main() and some top-level functions */
  4. /* omega.c */
  5.  
  6. #if !defined(MSDOS) || defined(DJGPP)
  7. #include <signal.h>
  8. #include <fcntl.h>
  9. #include <time.h>
  10. #include <unistd.h>
  11. #include <stdlib.h>
  12. /* Note: in order to avoid a memory bug I've been told about, I'm
  13.    explicitly initializing every global to something. */
  14. #endif
  15.  
  16. #include "glob.h"
  17.  
  18. /* most globals originate in omega.c */
  19.  
  20. char *Omegalib;        /* contains the path to the library files */
  21.  
  22. /* Objects and Monsters are allocated and initialized in init.c */
  23.  
  24. /* one of each spell */
  25. #ifndef MSDOS
  26. struct spell Spells[NUMSPELLS+1];
  27. #else
  28. struct spell Spells[NUMSPELLS+1] = {0};
  29. #endif
  30.  
  31. /* locations of city sites [0] - found, [1] - x, [2] - y */
  32. #ifndef MSDOS
  33. int CitySiteList[NUMCITYSITES][3];
  34. #else
  35. int CitySiteList[NUMCITYSITES][3] = {0};
  36. #endif
  37.  
  38. /* Currently defined in caps since it is now a variable, was a constant */
  39. int LENGTH=MAXLENGTH; 
  40. int WIDTH=MAXWIDTH;
  41.  
  42. long GameStatus=0L;                   /* Game Status bit vector */
  43. int ScreenLength = 0;                 /* How large is level window */
  44. #ifndef MSDOS
  45. struct player Player;                 /* the player */
  46. #else
  47. struct player Player = {0};           /* the player */
  48. #endif
  49. #ifndef MSDOS
  50. struct terrain Country[MAXWIDTH][MAXLENGTH];/* The countryside */
  51. #else
  52. struct terrain Country[MAXWIDTH][MAXLENGTH] = {0};/* The countryside */
  53. #endif
  54. #ifdef SAVE_LEVELS
  55. struct level TheLevel;
  56. #endif
  57. struct level *City=NULL;              /* The city of Rampart */
  58. struct level *TempLevel=NULL;         /* Place holder */
  59. struct level *Level=NULL;             /* Pointer to current Level */
  60. struct level *Dungeon=NULL;           /* Pointer to current Dungeon */
  61. int Villagenum = 0;                   /* Current Village number */ 
  62. int ScreenOffset = 0;                 /* Offset of displayed screen to level */
  63. int MaxDungeonLevels = 0;             /* Deepest level allowed in dungeon */
  64. int Current_Dungeon= -1;              /* What is Dungeon now */
  65. int Current_Environment= E_CITY;      /* Which environment are we in */
  66. int Last_Environment= E_COUNTRYSIDE;  /* Which environment were we in */
  67. #ifndef MSDOS
  68. int Dirs[2][9];                       /* 9 xy directions */
  69. #else
  70. int Dirs[2][9]=                       /* 9 xy directions */
  71.   { { 1,1,-1,-1,1,-1,0,0,0} , { 1,-1,1,-1,0,0,1,-1,0 } };
  72. #endif
  73. char Cmd='s';                         /* last player command */
  74. int Command_Duration = 0;             /* how long does current command take */
  75. struct monster *Arena_Monster=NULL;   /* Opponent in arena */
  76. int Arena_Opponent=0;                 /* case label of opponent in l_arena()*/
  77. int Arena_Victory = 0;                /* did player win in arena? */
  78. int Imprisonment=0;                   /* amount of time spent in jail */
  79. int Precipitation=0;                  /* Hours of rain, snow, etc */
  80. int Lunarity=0;                       /* Effect of the moon on character */
  81. int Phase = 0;                        /* Phase of the moon */
  82. int Date = 0;                         /* Starting date */
  83. int Pawndate = 0;                     /* Pawn Shop item generation date */
  84. pob Pawnitems[PAWNITEMS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  85. /* items in pawn shop */
  86. int SymbolUseHour= -1;                /* holy symbol use marker */
  87. int ViewHour= -1;                     /* crystal ball use marker */
  88. int ZapHour= -1;                      /* staff of enchantment use marker */
  89. int HelmHour= -1;                     /* helm of teleportation use marker*/
  90. int Constriction=0;                   /* Dragonlord Attack State */
  91. int Blessing=FALSE;                   /* Altar Blessing State */
  92. int LastDay= -1;                      /* DPW date of dole */
  93. int RitualHour= -1;                   /* last use of ritual magic */
  94. int RitualRoom= -1;                   /* last room of ritual magic */
  95. int Lawstone=0;                       /* magic stone counter */
  96. int Chaostone=0;                      /* magic stone counter */
  97. int Mindstone=0;                      /* magic stone counter */
  98. int Searchnum = 1;                    /* number of times to search on 's' */
  99. int Behavior;                  /* Player NPC behavior */
  100. int Verbosity = VERBOSE;              /* verbosity level */
  101. char Seed;                            /* random seed */
  102. long Time = 0;                        /* turn number */
  103. int Tick = 0;                         /* 10 a turn; action coordinator */
  104. char Stringbuffer[STRING_BUFFER_SIZE][80];    /* last strings printed */
  105. long Gymcredit = 0;                   /* credit at rampart gym */
  106. int Spellsleft = 0;                   /* research allowance at college */
  107. int StarGemUse = 0;                   /* last date of star gem use */
  108. int HiMagicUse = 0;                   /* last date of high magic use */
  109. int HiMagic = 0;                      /* current level for l_throne */ 
  110. long Balance = 0;                     /* bank account */
  111. long FixedPoints = 0;                 /* points are frozen after adepthood*/
  112. int LastTownLocX=0;            /* previous position in village or city */
  113. int LastTownLocY=0;            /* previous position in village or city */
  114. int LastCountryLocX=0;            /* previous position in countryside */
  115. int LastCountryLocY=0;            /* previous position in countryside */
  116. #ifndef MSDOS
  117. char Password[64];                    /* autoteller password */
  118. #else
  119. char Password[64] = {0};              /* autoteller password */
  120. #endif
  121. #ifndef MSDOS
  122. char Str1[STRING_LEN],Str2[STRING_LEN],Str3[STRING_LEN],Str4[STRING_LEN];
  123. #else
  124. char Str1[STRING_LEN] = {0},Str2[STRING_LEN] = {0},Str3[STRING_LEN] = {0},Str4[STRING_LEN] = {0};
  125. #endif
  126.    /* Some string space, random uses */
  127.  
  128. pol Condoitems=NULL;                        /* Items in condo */
  129.  
  130. /* high score names, levels, behavior */
  131. #ifndef MSDOS
  132. int Shadowlordbehavior,Archmagebehavior,Primebehavior,Commandantbehavior;
  133. int Championbehavior,Priestbehavior[7],Hibehavior,Dukebehavior;
  134. int Chaoslordbehavior,Lawlordbehavior,Justiciarbehavior;
  135. char Shadowlord[80],Archmage[80],Prime[80],Commandant[80],Duke[80];
  136. char Champion[80],Priest[7][80],Hiscorer[80],Hidescrip[80];
  137. char Chaoslord[80],Lawlord[80],Justiciar[80];
  138. int Shadowlordlevel,Archmagelevel,Primelevel,Commandantlevel,Dukelevel;
  139. #else
  140. int Shadowlordbehavior = 0,Archmagebehavior = 0,Primebehavior = 0,Commandantbehavior = 0;
  141. int Championbehavior = 0,Priestbehavior[7] = {0},Hibehavior = 0,Dukebehavior = 0;
  142. int Chaoslordbehavior = 0,Lawlordbehavior = 0,Justiciarbehavior = 0;
  143. char Shadowlord[80] = {0},Archmage[80] = {0},Prime[80] = {0},Commandant[80] = {0},Duke[80] = {0};
  144. char Champion[80] = {0},Priest[7][80] = {0},Hiscorer[80] = {0},Hidescrip[80] = {0};
  145. char Chaoslord[80] = {0},Lawlord[80] = {0},Justiciar[80] = {0};
  146. int Shadowlordlevel = 0,Archmagelevel = 0,Primelevel = 0,Commandantlevel = 0,Dukelevel = 0;
  147. #endif
  148. #ifndef MSDOS
  149. int Championlevel,Priestlevel[7],Hilevel,Justiciarlevel;
  150. #else
  151. int Championlevel = 0,Priestlevel[7] = {0},Hilevel = 0,Justiciarlevel = 0;
  152. #endif
  153. long Hiscore = 0L;
  154. int Chaoslordlevel = 0,Lawlordlevel = 0,Chaos = 0,Law = 0;
  155.  
  156. /* New globals which used to be statics */
  157. int twiddle = FALSE;
  158. int saved=FALSE;
  159. int onewithchaos=FALSE;
  160. int club_hinthour = 0;
  161. int winnings = 0;
  162. int tavern_hinthour;
  163. int scroll_ids[30];
  164. int potion_ids[30];
  165. int stick_ids[30];
  166. int ring_ids[30];
  167. int cloak_ids[30];
  168. int boot_ids[30];
  169.  
  170. int deepest[E_MAX + 1];
  171. int level_seed[E_MAX + 1];    /* random number seed that generated level */
  172.  
  173. /* This may be implementation dependent */
  174. /* SRANDFUNCTION is defined in odefs.h */
  175. /* environment is the environment about to be generated, or -1 for the first */
  176. /* time, or -2 if we want to restore the random number point */
  177. void initrand(int environment, int level)
  178. {
  179.   static int store;
  180.  
  181.   if (environment >= 0)
  182.     store = RANDFUNCTION;
  183.   /* Pseudo Random Seed */
  184.   if (environment == -1)
  185.     Seed = (int) time((long *)NULL);
  186.   else if (environment == -2)
  187.     Seed = store;
  188.   else
  189.     Seed = level_seed[environment] + 1000*level;
  190.   SRANDFUNCTION;
  191. }
  192.  
  193.  
  194. int game_restore(argc,argv)
  195. int argc;
  196. char *argv[];
  197. {
  198.   char savestr[80];
  199.   int ok;
  200.   if (argc==2) {
  201.     strcpy(savestr,argv[1]);
  202.     ok = restore_game(savestr);
  203.     if (! ok) {
  204.       endgraf();
  205.       printf("Try again with the right save file, luser!\n");
  206.       exit(0);
  207.     }
  208.     change_to_user_perms();
  209.     unlink(savestr);
  210.     change_to_game_perms();
  211.     return(TRUE);
  212.   }
  213.   else return(FALSE);
  214. }
  215.  
  216.  
  217. int main(argc,argv)
  218. int argc;
  219. char *argv[];
  220. {
  221.   int continuing;
  222.   int count;
  223.  
  224.  
  225.   /* always catch ^c and hang-up signals */
  226.  
  227. #ifdef SIGINT
  228.   signal(SIGINT,(void *)quit);
  229. #endif
  230. #ifdef SIGHUP
  231.   signal(SIGHUP,(void *)signalsave);
  232. #endif
  233.  
  234. #ifndef MSDOS
  235.   if (CATCH_SIGNALS) {
  236.     signal(SIGQUIT,(void *)signalexit);
  237.     signal(SIGILL,(void *)signalexit);
  238. #ifndef AMIGA
  239.     signal(SIGTRAP,(void *)signalexit);
  240. #endif
  241.     signal(SIGFPE,(void *)signalexit);
  242.     signal(SIGSEGV,(void *)signalexit);
  243. #ifdef SIGIOT
  244.     signal(SIGIOT,(void *)signalexit);
  245. #endif
  246. #ifdef SIGABRT
  247.     signal(SIGABRT,(void *)signalexit);
  248. #endif
  249. #ifdef SIGEMT
  250.     signal(SIGEMT,(void *)signalexit);
  251. #endif
  252. #ifdef SIGBUS
  253.     signal(SIGBUS,(void *)signalexit);
  254. #endif
  255. #ifdef SIGSYS
  256.     signal(SIGSYS,(void *)signalexit);
  257. #endif
  258.     }
  259. #endif
  260.  
  261. #ifndef FIXED_OMEGALIB
  262.   if (!(Omegalib = getenv("OMEGALIB")))
  263. #endif
  264.     Omegalib = OMEGALIB;
  265.  
  266.   /* if filecheck is 0, some necessary data files are missing */
  267.   if (filecheck() == 0) exit(0);
  268.  
  269.   /* all kinds of initialization */
  270.   init_perms();
  271.   initgraf();
  272. #ifndef MSDOS
  273.   initdirs();
  274. #endif
  275.   initrand(-1, 0);
  276.   initspells();
  277.  
  278.   for (count = 0; count < STRING_BUFFER_SIZE; count++)
  279.     strcpy(Stringbuffer[count],"<nothing>");
  280.  
  281. #ifdef SAVE_LEVELS
  282.   msdos_init();
  283. #endif
  284.  
  285.   /* game restore attempts to restore game if there is an argument */
  286.   continuing = game_restore(argc,argv);
  287.  
  288.   /* monsters initialized in game_restore if game is being restored */  
  289.   /* items initialized in game_restore if game is being restored */
  290.   if (! continuing) {
  291.     inititem(TRUE);
  292.     Date = random_range(360);
  293.     Phase = random_range(24);
  294.     strcpy(Password,"");
  295.     initplayer();
  296.     init_world();
  297.     mprint("'?' for help or commandlist, 'Q' to quit.");
  298.   }
  299.   else mprint("Your adventure continues....");
  300.  
  301.   timeprint();
  302.   calc_melee();
  303.   if (Current_Environment != E_COUNTRYSIDE)
  304.     showroom(Level->site[Player.x][Player.y].roomnumber);
  305.   else
  306.     terrain_check(FALSE);
  307.   
  308.   if (optionp(SHOW_COLOUR))
  309.     colour_on();
  310.   else
  311.     colour_off();
  312.  
  313.   screencheck(Player.y);
  314.  
  315.  /* game cycle */
  316.   if (!continuing)
  317.     time_clock(TRUE);
  318.   while (TRUE) {
  319.     if (Current_Environment == E_COUNTRYSIDE)
  320.       p_country_process();
  321.     else time_clock(FALSE);
  322.   }
  323. }
  324.  
  325. #ifndef MSDOS
  326. void signalexit()
  327. {
  328.   clearmsg();
  329.   mprint("Yikes!");
  330.   morewait();
  331.   mprint("Sorry, caught a core-dump signal.");
  332.   mprint("Want to try and save the game?");
  333.   if (ynq()=='y')
  334.     save(FALSE, TRUE); /* don't compress, force save */
  335.   mprint("Bye!");
  336.   endgraf();
  337.   exit(0);
  338. }
  339. #endif
  340.  
  341.  
  342.  
  343.  
  344. /* Start up game with new dungeons; start with player in city */
  345. void init_world()
  346. {
  347.   int env, i;
  348.  
  349.   City = Level = TempLevel = Dungeon = NULL;
  350.   for (env = 0; env <= E_MAX; env++)
  351.     level_seed[env] = RANDFUNCTION;
  352.   load_country();
  353.   for(i=0;i<NUMCITYSITES;i++) 
  354.     CitySiteList[i][0] = FALSE;
  355.   load_city(TRUE);
  356.   WIDTH = 64;
  357.   LENGTH = 64;
  358.   Player.x = 62;
  359.   Player.y = 21;
  360.   Level = City;
  361.   Current_Environment = E_CITY;
  362.   print1("You pass through the massive gates of Rampart, the city.");  
  363. }
  364.  
  365. /* set variable item names */
  366. void inititem(reset)
  367. int reset;
  368. {
  369.   int i;
  370.  
  371.   if (reset) {
  372.     shuffle(scroll_ids, 30);
  373.     shuffle(potion_ids, 20);
  374.     shuffle(stick_ids, 20);
  375.     shuffle(boot_ids, 20);
  376.     shuffle(cloak_ids, 20);
  377.     shuffle(ring_ids, 20);
  378.   }
  379.   for(i=0;i<NUMSCROLLS;i++)
  380.     Objects[SCROLLID+i].objstr = scrollname(i);
  381.   for(i=0;i<NUMPOTIONS;i++)
  382.     Objects[POTIONID+i].objstr = potionname(i);
  383.   Objects[ARTIFACTID + 10].objstr = potionname(18);
  384.   Objects[ARTIFACTID + 13].objstr = potionname(19);
  385.   for(i=0;i<NUMSTICKS;i++)
  386.     Objects[STICKID+i].objstr = stickname(i);
  387.   for(i=0;i<NUMBOOTS;i++)
  388.     Objects[BOOTID+i].objstr = bootname(i);
  389.   for(i=0;i<NUMCLOAKS;i++)
  390.     Objects[CLOAKID+i].objstr = cloakname(i);
  391.   for(i=0;i<NUMRINGS;i++)
  392.     Objects[RINGID+i].objstr = ringname(i);
  393. }
  394.